<?php

class AppController extends Controller {
    var $components = array(
		'Acl',
		'AutoLogin',
		'Auth' => array(
			'authorize' => 'actions',
			//'loginAction' => array('controller' => 'welcome'),
        	//'logoutRedirect' => array('controller' => 'welcome'),
        	//'loginRedirect' => '/',
        	'actionPath' => 'controllers/',
			//Il login avviene con e-mail e password
        	'fields' => array(
				'username' => 'email',
				'password' => 'password'
			),
			//Il login avviene solo se l'utente è attivo
        	'userScope' => array(
				'User.active' => true
			),
		),
		'Session',
		'RequestHandler',
		'P28n',
	);
    var $helpers = array('Html', 'Javascript', 'Form', 'Session');
    
    function beforeFilter() {
		parent::beforeFilter();
		
		if ($this->RequestHandler->isAjax())
		{
			Configure::write('debug', 0);
			$this->disableCache();

			// If not from this domain, destroy
			if (($this->allowRemoteRequests === false) && (strpos(env('HTTP_REFERER'), trim(env('HTTP_HOST'), '/')) === false))
			{
				if (isset($this->Controller->Security))
				{
					$this->Controller->Security->blackHole($this->Controller, 'Invalid referrer detected for this request!');
				}
				else
				{
					$this->Controller->redirect(null, 403, true);
				}
			}
		}
		elseif (isset($this->params['admin']) && !empty($this->params['admin']))
		{
			$this->layout = 'admin';
		}
	}
}

?>
